package world.criver.h50529.data;

import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;

public class daFxml {
    public static BorderPane master;
    public static BorderPane page1;
    public static BorderPane page2;
    public static BorderPane page2Add;
    public static BorderPane page3;
    public static BorderPane page3Add;
    public static BorderPane page4;
    public static BorderPane page5;
    public static BorderPane page5AddGroup;
    public static VBox popMenu;
    public static void ini(){
        try{
            loadMaster();
            loadPage1();
            loadPage2();
            loadPage2Add();
            loadPage3();
            loadPage3Add();
            loadPage4();
            loadPage5();
            loadPage5AddGroup();
            loadPopMenu();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
    private static void loadMaster() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"master.fxml"));
        master=loader.load();
        daControllers.master=loader.getController();
    }
    private static void loadPage1() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page1.fxml"));
        page1=loader.load();
        daControllers.page1=loader.getController();
    }
    private static void loadPage2() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page2.fxml"));
        page2=loader.load();
        daControllers.page2=loader.getController();
    }
    private static void loadPage2Add() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page2Add.fxml"));
        page2Add=loader.load();
        daControllers.page2Add=loader.getController();
    }
    private static void loadPage3() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page3.fxml"));
        page3=loader.load();
        daControllers.page3=loader.getController();
    }
    private static void loadPage3Add() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page3Add.fxml"));
        page3Add=loader.load();
        daControllers.page3Add=loader.getController();
    }
    private static void loadPage4() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page4.fxml"));
        page4=loader.load();
        daControllers.page4=loader.getController();
    }
    private static void loadPage5() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page5.fxml"));
        page5=loader.load();
        daControllers.page5=loader.getController();
    }
    private static void loadPage5AddGroup() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"page5AddGroup.fxml"));
        page5AddGroup=loader.load();
        daControllers.page5AddGroup=loader.getController();
    }
    private static void loadPopMenu() throws IOException {
        FXMLLoader loader=new FXMLLoader(daFxml.class.getResource(daData.resources_fxml_path+"popMenu.fxml"));
        popMenu=loader.load();
        daControllers.popMenu=loader.getController();
        Stage child=new Stage();
        Scene sc=new Scene(popMenu);
        sc.setFill(null);
        child.setScene(sc);
        child.initStyle(StageStyle.TRANSPARENT);
        child.setAlwaysOnTop(true);
        daData.popMenu=child;
        Stage parent=new Stage();
        parent.initStyle(StageStyle.UTILITY);
        parent.setOpacity(0);
        daData.popMenuParent=parent;
        child.initOwner(parent);
        parent.show();
        parent.setWidth(child.getWidth());
        parent.setHeight(child.getHeight());
        child.focusedProperty().addListener((e,o,n)->{
            if(!n)daData.popMenu.hide();
        });
    }
}
